#include "../include/log/logger.hpp"

// int main()
// {
//     // /* 初步测试 */
//     // // 日志器参数
//     // std::string logger_name = "sync_logger";
//     // log_system::LogLevel::Level limit_level = log_system::LogLevel::Level::WARNING;
//     // log_system::Formatter::pointer formatter(new log_system::Formatter());

//     // // 三个不同输出位置
//     // log_system::LogSink::pointer stdout_ptr = log_system::LogSinkFactory::create<log_system::StdoutLogSink>();
//     // log_system::LogSink::pointer file_ptr = log_system::LogSinkFactory::create<log_system::SpecifyFileLogSink>("./logfile/test.log");
//     // log_system::LogSink::pointer scrollfilebusize_ptr = log_system::LogSinkFactory::create<log_system::ScrollFileBySizeLogSink>("./logfile/scrollbysize-", 1024 * 1024);

//     // // 日志器生成
//     // std::vector<log_system::LogSink::pointer> sinks = {stdout_ptr, file_ptr, scrollfilebusize_ptr};
//     // // for(auto& ptr : sinks)
//     // // {
//     // //     std::cout << "sinks have: " << ptr << std::endl;
//     // // }
//     // log_system::Logger::pointer logger(new log_system::SyncLogger(logger_name, limit_level, formatter, sinks));

//     // logger->debug(__FILE__, __LINE__, "%s", "DEBUG测试日志");
//     // logger->info(__FILE__, __LINE__, "%s", "INFO测试日志");
//     // logger->warning(__FILE__, __LINE__, "%s", "WARNING测试日志");
//     // logger->error(__FILE__, __LINE__, "%s", "ERROR测试日志");
//     // logger->fatal(__FILE__, __LINE__, "%s", "FATAL测试日志");

//     // size_t current_size = 0, count = 0;
//     // while (current_size < 1024 * 1024 * 10)
//     // {
//     //     logger->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
//     //     current_size += 20;
//     // }

//     // /* 测试建造者模式 */
//     // std::unique_ptr<log_system::LoggerBuilder> builder(new log_system::LocalLoggerBuilder());
//     // builder->buildLoggerType(log_system::LoggerBuilder::Type::LOGGER_SYNC);
//     // builder->buildLoggerLevel(log_system::LogLevel::Level::WARNING);
//     // builder->buildLoggerName("SYNC_LOGGER");
//     // builder->buildFormatter("%m%n");
//     // builder->buildLoggerSink<log_system::SpecifyFileLogSink>("./logfile/test.log");
//     // builder->buildLoggerSink<log_system::StdoutLogSink>();
//     // log_system::Logger::pointer logger = builder->build();
//     // logger->debug(__FILE__, __LINE__, "%s", "DEBUG测试日志");
//     // logger->info(__FILE__, __LINE__, "%s", "INFO测试日志");
//     // logger->warning(__FILE__, __LINE__, "%s", "WARNING测试日志");
//     // logger->error(__FILE__, __LINE__, "%s", "ERROR测试日志");
//     // logger->fatal(__FILE__, __LINE__, "%s", "FATAL测试日志");

//     // size_t current_size = 0, count = 0;
//     // while (current_size < 1024 * 1024 * 10)
//     // {
//     //     logger->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
//     //     current_size += 80;
//     // }

//     std::unique_ptr<log_system::LoggerBuilder> builder(new log_system::LocalLoggerBuilder());
//     builder->buildLoggerType(log_system::LoggerBuilder::Type::LOGGER_ASYNC);
//     builder->buildLoggerLevel(log_system::LogLevel::Level::WARNING);
//     builder->buildLoggerName("ASYNC_LOGGER");
//     builder->buildFormatter("[%c]%m%n");
//     builder->buildLoggerSink<log_system::SpecifyFileLogSink>("./logfile/async.log");
//     builder->buildLoggerSink<log_system::StdoutLogSink>();
//     builder->buildUnsafeAsyncWorker();
//     log_system::Logger::pointer logger = builder->build();
//     logger->debug(__FILE__, __LINE__, "%s", "DEBUG测试日志");
//     logger->info(__FILE__, __LINE__, "%s", "INFO测试日志");
//     logger->warning(__FILE__, __LINE__, "%s", "WARNING测试日志");
//     logger->error(__FILE__, __LINE__, "%s", "ERROR测试日志");
//     logger->fatal(__FILE__, __LINE__, "%s", "FATAL测试日志");

//     size_t current_size = 0, count = 0;
//     while (current_size < 1024 * 1024 * 10)
//     {
//         logger->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
//         current_size += 20;
//     }

//     return 0;
// }

// 测试全局日志器建造者
void testGlobalLoggerBuilder()
{
    log_system::Logger::pointer logger = log_system::LoggerManager::getInstance().getLogger("ASYNC_LOGGER");

    logger->debug(__FILE__, __LINE__, "%s", "DEBUG测试日志");
    logger->info(__FILE__, __LINE__, "%s", "INFO测试日志");
    logger->warning(__FILE__, __LINE__, "%s", "WARNING测试日志");
    logger->error(__FILE__, __LINE__, "%s", "ERROR测试日志");
    logger->fatal(__FILE__, __LINE__, "%s", "FATAL测试日志");
    size_t current_size = 0, count = 0;
    while (current_size < 1024 * 1024 * 10)
    {
        logger->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
        current_size += 20;
    }
}

int main()
{
    // std::unique_ptr<log_system::LoggerBuilder> builder(new log_system::GlobalLoggerBuilder());
    // builder->buildLoggerType(log_system::LoggerBuilder::Type::LOGGER_ASYNC);
    // builder->buildLoggerLevel(log_system::LogLevel::Level::WARNING);
    // builder->buildLoggerName("ASYNC_LOGGER");
    // builder->buildFormatter("[%c]%m%n");
    // builder->buildLoggerSink<log_system::SpecifyFileLogSink>("./logfile/async.log");
    // builder->buildLoggerSink<log_system::StdoutLogSink>();
    // builder->buildUnsafeAsyncWorker();
    // builder->build();
    // testGlobalLoggerBuilder();

    // log_system::LoggerDirector direator("master");
    // log_system::LogSinkSet set(direator.getLoggerBuilder());
    // set.set(log_system::StdoutLogSink());
    // set.set(log_system::SpecifyFileLogSink(), "./logfile/sync.log");
    // set.set(log_system::ScrollFileBySizeLogSink(), "./srcollLogfile/", 1024 * 1024);
    // set.set(log_system::ScrollFileByTimeLogSink(), "./scrollByTime/", log_system::ScrollFileByTimeLogSink::GAP_SECOND);

    // log_system::LoggerDirector director("master", log_system::LoggerDirector::BuilderCategory::GLOBAL_BUILDER, log_system::LoggerBuilder::LOGGER_ASYNC);
    // log_system::LogSinkSet set(director.getLoggerBuilder());
    // // set.set(log_system::StdoutLogSink());
    // set.set(log_system::ScrollFileBySizeLogSink(), "./srcollLogfile/", 1024 * 1024);
    // log_system::Logger::pointer logger = director.create();
    // // std::cout << "logger : " << director.getLogger().get() << std::endl;

    // // director.getLogger()->debug(__FILE__, __LINE__, "%s", "DEBUG测试日志");

    // size_t current_size = 0, count = 0;
    // while (current_size < 1024 * 1024 * 10)
    // {
    //     director.getLogger()->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
    //     current_size += 20;
    // }

    log_system::LoggerDirector director("test1_logger", log_system::LoggerDirector::BuilderCategory::LOCAL_BUILDER, log_system::LoggerBuilder::LOGGER_SYNC, log_system::LogLevel::DEBUG);
    log_system::LogSinkSet set(director.getLoggerBuilder());
    set.set(log_system::StdoutLogSink());
    set.set(log_system::SpecifyFileLogSink(), "./logfile/test1.log");

    director.getLogger()->info( __FILE__,__LINE__, "%s", "scope : main()");

    return 0;
}
